<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>	
		<style type="text/css">
			#title{
				margin-top:15px;
			}
			#table_result table tr{
				
			}
			#table_result table{
                font-family:Georgia, "Times New Roman", Times, serif;
                border: 1px solid #555;
                color: #555;
                border-collapse: collapse;
            }
           #table_result table tr{
                	border: 1px solid #555;
                	color: #555;
            }
            #table_result table th{
                	border: 1px solid #555;
                	color: #555;
            }
           #table_result table td{
                    border: 1px solid #555;
                    color: #555;
            }
		</style>
  </head>
  <body>
    <div id="main">
    	<s:if test="#request.add != null ">
			<div id="title"><h4><s:text name="resource.save.upload.resource" /></h4></div>
			<hr />
			<p><s:text name="resource.save.please" /></p>
			<div id="uploadform">
			<table>
				<s:form action="resource/uploadResource.action" method="post" enctype="multipart/form-data" theme="simple">
					<tr><td><s:text name="resource.save.name" /></td>
						<td><s:textfield name="teachingSupportResource.name" label="Name" cssClass="textfield_uploadname"/></td>
					</tr>
					<tr><td><s:text name="resource.save.course" /></td>
						<td><s:select id="chooseCourse" label="Course" name="teachingSupportResource.courseName"
							list="#request.CourseNames" listKey="name" listValue="name" headerKey="-1" headerValue="Select Course"  value="%{#request.courseId}"
							/></td>
					</tr>
					<tr><td><s:text name="resource.save.resource" /></td>
		    			<td><s:file name="resource" label="Resource" /></td>
		    		</tr>
		    		<tr><td><s:text name="resource.save.describe" /></td>
		    			<td><s:textarea name="teachingSupportResource.describe" label="Describe" /></td>
		    		</tr><tr><td>&nbsp;</td>
		    			<td><s:submit /></td></tr>
		    	</s:form>
		    </table>
		    <s:if test="#request.addresource_success != null ">
		    	<h4><s:text name="resource.save.upload.success" /></h4>
		    </s:if>
	    	</div>
		</s:if>	
			<!-- 查询资源 -->
		<s:if test="#request.search != null ">
				
			<s:if test="#request.delete != null">
				<div id="title"><h4><s:text name="resource.delete.delete.resources" /></h4></div>
			</s:if>
			<s:else>
				<div id="title"><h4><s:text name="resource.search.search.resources" /></h4></div>
			</s:else>
			<hr />
			<s:if test="#request.delete != null">
				<h5><s:text name="resource.delete.before.you.delete" /></h5>
			</s:if>
			<s:if test="#request.beforemodify != null ">
				<h5><s:text name="resource.modify.modify.you.delete" /></h5>
			</s:if>
			<div id="searchForm">
			<s:form action="resource/searchResource.action" method="post" theme="simple">                     
		           <s:submit id="sbutton"  value="Search" />
		           <s:textfield id="ssearchtext"  name="searchText" size="22"/>
		           <div id="searchcheck">
		           		<s:radio name="searchRadio" list="#{'all':'all','name':'name','cname':'cname','blear':'blear'}" value="'all'" />
		           </div>
             </s:form>	
             </div>		
             	<s:if test="#request.deletesuccess != null"><h4><s:text name="resource.delete.delete.success" /></h4></s:if>
             	<s:if test="#request.modifysuccess != null"><h4><s:text name="resource.modify.modify.success" /></h4></s:if>
             	<s:if test="#request.searchhavedata != null ">
					<div id="table_result">
             		<table id="searchTable" border="1">
					<tr>					
						<th><s:text name="resource.search.name" /></th>
						<th><s:text name="resource.search.course" /></th>
						<th><s:text name="resource.search.time" /></th>
						<th><s:text name="resource.search.detail" /></th>
						<s:if test="%{#session.SESSION_USERTYPE != 'instructor'}"><th><s:text name="resource.search.modify" /></th></s:if>
						<s:if test="%{#session.SESSION_USERTYPE != 'instructor'}"><th><s:text name="resource.search.delete" /></th></s:if>
						<th><s:text name="resource.search.download" /></th>
					</tr>
					<s:iterator  value="#request.allResource">
						<tr>
							<td><s:property value="name"/></td>
							<td><s:property value="courseName"/></td>
							<td><s:property value=""/></td>
							<td><s:property value="describe"/></td>
							<s:if test="%{#session.SESSION_USERTYPE != 'instructor'}"><td><button id="sbutton" onclick="modifyResource('<s:property value="id"/>','<s:property value="name"/>','<s:property value="courseName"/>','<s:property value="describe"/>');">Modify</button></td></s:if>
							<s:if test="%{#session.SESSION_USERTYPE != 'instructor'}"><td><button id="sbutton" onclick="deleteResource('<s:property value="id"/>','<s:property value="fileName"/>');">Delete</button></td></s:if>
							<td><button id="sbutton" onclick="downloadResource('<s:property value="fileName"/>');">Download</button></td>
						</tr>
					</s:iterator>	
					</table>
					</div>						
				
				</s:if>
             	<s:if test="#request.searchnodata != null ">
             		<div id="nodata"><h4><s:text name="resource.search.no.data" /></h4></div>
             	</s:if>
		</s:if>	
		<!-- 修改资源信息, -->
           <s:if test="#request.modify != null ">
             	<div id="title"><h4>
				<s:text name="resource.modify.modify.resource" />
			</h4></div><hr />
			
			<p><s:text name="resource.modify.modify.please" /></p>
			<div id="uploadform">
			<table>
				<s:form action="resource/modifyResource.action" method="post" theme="simple">
					<tr><td><s:text name="resource.save.name" /></td>
						<td><s:textfield name="teachingSupportResource.name" label="Name" cssClass="textfield_uploadname" value="%{#request.name}"/></td>
					</tr>
					<tr><td><s:text name="resource.save.course" /></td>
						<td><s:select id="chooseCourse" label="Course" name="teachingSupportResource.courseName"
							list="#request.CourseNames" listKey="name" listValue="name" headerKey="-1" headerValue="Select Course"  value="%{#request.courseName}"
							onchange="showCourseDetail()" /></td>
					</tr>
					<tr><td><s:text name="resource.save.resource" /></td>
		    			<td><s:file name="resource" label="Resource" disabled="true"/></td>
		    		</tr>
		    		<tr><td><s:text name="resource.save.describe" /></td>
		    			<td><s:textarea name="teachingSupportResource.describe" label="Describe"  value="%{#request.describe}"/></td>
		    		</tr><tr><td>&nbsp;</td>
		    		<s:hidden name="teachingSupportResource.id" value="%{#request.id}"></s:hidden>
		    			<td><s:submit /></td></tr>
		    	</s:form>
		    </table>
	    	</div>
         </s:if>
	</div>
  </body>
</html>
